-- Neovim Configuration Module: Keymap for Headful Instances --
local default_opts = {
	silent = true,
}

local keymap = {
	--- Folds ---
	{
		'', '<Tab>',
		'za',
		{ desc = 'Toggle fold under cursor' },
	},

	--- Files/Buffers ---
	{
		'', 'q',
		'',
	},
	{
		'', 'Q',
		vim.cmd.bdelete,
		{ desc = 'Delete current buffer' },
	},
	{
		'', 'gb',
		function()
			if vim.fn.buflisted(0) == 1 then
				return '<C-^>'
			else
				return ''
			end
		end,
		{
			expr = true,
			desc = 'Edit alternate file if it\'s in the buffer list',
		},
	},
	{
		'', '<Leader>l',
		function() ToggleOption 'wrap' end,
		{ desc = 'Toggle line wrap' },
	},

	--- Windows ---
	{
		'', 'gw',
		'<C-w>w',
		{ desc = 'Clock-wise move around windows' },
	},
	{
		'', '<Leader>0',
		vim.cmd.close,
		{ desc = 'Close current window' },
	},
	{
		'', '<Leader>1',
		vim.cmd.only,
		{ desc = 'Keep only current window' },
	},
	{
		'', '<Leader>2',
		vim.cmd.split,
		{ desc = 'Split current window' },
	},
	{
		'', '<Leader>3',
		vim.cmd.vsplit,
		{ desc = 'Vertically split current window' },
	},
	{
		'', '<Leader>w',
		'<C-w>',
	},

	--- Other UI Components ---
	{
		'', '<Leader>t',
		vim.cmd.tabnew,
		{ desc = 'Open new tab page' },
	},
	{
		'', '<Leader>T',
		VimCommand 'horizontal terminal',
		{ desc = 'Open terminal emulator' },
	},

	--- LSP ---
	{
		'n', 'grf',
		vim.lsp.buf.format,
		{ desc = 'Formats buffer with LSP' },
	},
}

BindKeys(keymap, default_opts)
